package com.atguigu.sort;

/**
 * @author xgc
 * @create 2021-07-22 9:36
 * 冒泡排序
 */
public class BubbleSort {
    public static void bubbleSort(int[] data){
        int arrayLength = data.length;
        for (int i = 1; i <  arrayLength; i++) {
            for (int j = 0 ; j < arrayLength - i ; j++){
             if (data[j] > data[j+1]){
                 int temp = data[j];
                 data[j] = data[j+1];
                 data[j+1] = temp;
             }
            }
            System.out.println("第" + i + "次排序：\n" + java.util.Arrays.toString(data));
        }
        
    }

    public static void main(String[] args) {
        int[] data = {3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48};
        System.out.println("排序之前：\n" + java.util.Arrays.toString(data));
        bubbleSort(data);
        System.out.println("排序之后：\n" + java.util.Arrays.toString(data));
    }
}
